home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5775 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: druid.borland.com!usenet
  2. From: pete@borland.com (Pete Becker)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: weird behavior
  5. Date: 6 Feb 1996 19:53:01 GMT
  6. Organization: Borland International
  7. Message-ID: <4f8bit$i3k@druid.borland.com>
  8. References: <4ed10l$jap@news.csus.edu> <DM0EDv.9tF@news.arco.com>
  9. NNTP-Posting-Host: pbecker.borland.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <DM0EDv.9tF@news.arco.com>, lasbfl says...
  15. >
  16. >gustavo.sandoval@csus.edu (gustavo sandoval) wrote:
  17. >>I have the following linked list which I'm playing around with:
  18. >>
  19. >>class CList
  20. >>{
  21. >>public:
  22. >>   CList(); 
  23. >>   ~CList();
  24. >>
  25. >>   void Insert(int element);
  26. >>   void Print ();
  27. >>
  28. >>   // Returns the number or items deleted
  29. >>   int  Delete(int target);
  30. >>   
  31. >>private:
  32. >>   CItem* head;
  33. >>
  34. >>};// CList
  35. >>
  36. >>// Implementation of the functions omitted 
  37. >>
  38. >>// In main I have:
  39. >>
  40. >>void main ()
  41. >>{
  42. >>   CList MyList;
  43. >>
  44. >>   for (int x = 0; x < 10; x++ )
  45. >>      MyList.Insert (x*10);
  46. >>
  47. >>   MyList.Print();
  48. >>
  49. >>   int count = MyList.Delete (40);
  50. >>
  51. >>   MyList.Insert (50);
  52. >>   MyList.Insert;           // <== this lines
  53. >>   MyList.Print;            // <== this lines
  54. >>
  55. >>   count = MyList.Delete (50);
  56. >>
  57. >>}
  58. >>
  59. >>
  60. >>note the lines with the arrows.  The code compiles in VC 4.0 without 
  61. warnings 
  62. >>in level 4 or errors.  When I step through those two lines the debugger just 
  63. >>goes right by.  
  64. >
  65. >Gustavo,
  66. >
  67. >You should be getting compile errors. If I have read this correctly, you have
  68. >two lines which consist of functions pointers. Add the '()' function 
  69. operator,
  70. >and you should get your intended behaviour, although you are still missing 
  71. >the integral argument for the Insert function.
  72.  
  73. The reason for this is that Microsoft allows you to take the address of a 
  74. member function without using &. If you're inside a member function you also 
  75. don't need the class qualififer: it assumes that the name refers to the class 
  76. that you're in. This, of course, is totally non-standard behavior. Last time I 
  77. looked, MFC relied on it. That may have been fixed in MFC 4.0.
  78.     -- Pete
  79.  
  80.